package labox.innovation.log;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import labox.innovation.gameserver.util.StringUtil;

/**
 * @author zabbix
 * Lets drink to code!
 */
public class AuditFormatter extends Formatter {
	private static final String CRLF = "\r\n";

	private SimpleDateFormat dateFmt = new SimpleDateFormat("dd MMM H:mm:ss");

	@Override
	public String format(LogRecord record) {
		final Object[] params = record.getParameters();
		final StringBuilder output = StringUtil.startAppend(30 + record.getMessage().length() + (params == null ? 0 : params.length * 10), "[", dateFmt.format(new Date(record.getMillis())), "] ", record.getMessage());
		for (Object p : params) {
			if (p == null)
				continue;
			StringUtil.append(output, ", ", p.toString());
		}
		output.append(CRLF);
		return output.toString();
	}
}
